﻿using ConfExpert.Forms.Base;
using DevTeam;
using System;

namespace ConfExpert.Forms.Planlama
{
    public partial class BMByCustomer : XForm
    {
        public BMByCustomer()
        {
            InitializeComponent();
        }

        private void BMByCustomer_Load(object sender, EventArgs e)
        {
            gridView1.Init("GetBirimMetrajlar2");
            gridView1.AddDetailGrid(gridView2, "CustomerId");
            gridView2.AddDetailGrid(gridView3, "CustomerId,BaseModel,Line,Kalip");

            gridView3.AddColumn("ToplamMetraj", typeof(decimal), "Total*OrtBM");

            gridView2.AddColumn("ToplamGomlek", typeof(int), "SUM(Child({FK}).Total)");
            gridView2.AddColumn("ToplamMetraj", typeof(decimal), "SUM(Child({FK}).ToplamMetraj)");
            gridView2.AddColumn("OrtBM", typeof(decimal), "Iif(ToplamGomlek>0,ToplamMetraj/ToplamGomlek,null)");

            gridView1.AddColumn("ToplamGomlek", typeof(int), "SUM(Child({FK}).ToplamGomlek)");
            gridView1.AddColumn("ToplamMetraj", typeof(decimal), "SUM(Child({FK}).ToplamMetraj)");
            gridView1.AddColumn("OrtBM", typeof(decimal), "Iif(ToplamGomlek>0,ToplamMetraj/ToplamGomlek,null)");

            gridView1.MakeColumnInvisible("ToplamGomlek", "ToplamMetraj");
            gridView2.MakeColumnInvisible("ToplamGomlek", "ToplamMetraj");
            gridView3.MakeColumnInvisible("ToplamMetraj");

            gridView1.FormatAsNumber(0, "Adet");
            gridView2.FormatAsNumber(0, "Adet");

            gridView1.FormatAsNumber(3, "OrtBM");
            gridView2.FormatAsNumber(3, "OrtBM");
            gridView3.FormatAsNumber(3, "OrtBM");

            gridView1.AddSummary("Adet");
            gridView2.AddSummary("Adet");

            gridView1.MakeReadOnly();
            gridView2.MakeReadOnly();
            gridView3.MakeReadOnly();

            gridView1.FocusedRowChanged += gridView1_FocusedRowChanged;
            gridView2.FocusedRowChanged += gridView2_FocusedRowChanged;

            gridView1.BestFitColumns();
            gridView2.BestFitColumns();
            gridView3.BestFitColumns();

            gridView1.MakeRowSelectable();
        }

        void gridView2_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            gridView3.BestFitColumns();
        }

        void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            gridView2.BestFitColumns();
        }
    }
}
